//
//  Logger.m
//  FreeMessage
//
//  Created by Fox Guo on 12-7-10.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "Logger.h"
#import "HOUtils.h"
#import "Crashlytics/Crashlytics.h"

@implementation Logger

NSString *logPath;
static int LOG_LEVEL_BASE = LOG_LEVEL_DEBUG;

static NSTimeInterval recoredTime = 0;

void LogTo(LOG_LEVEL level,const char * func,size_t line,NSString * format,...)
{
    va_list args;
    va_start(args, format); 
    
    NSString* log = [[[NSString alloc] initWithFormat:format arguments:args] autorelease];
    
    NSString *logType;
    switch (level) {
        case LOG_LEVEL_INFO:
        {
            logType = LOG_INFO_STR;
        }
            break;
        case LOG_LEVEL_DEBUG:
        {
            logType = LOG_DEBUG_STR;
        }
            break;
        case LOG_LEVEL_NORMAL:
        {
            logType = LOG_NORMAL_STR;
        }
            break;
        case LOG_LEVEL_IMPORTANT:
        {
            logType = LOG_IMPORTANT_STR;
        }
            break;
        case LOG_LEVEL_WARNING:
        {
            logType = LOG_ERROR_STR;
        }
            break;
        case LOG_LEVEL_ERROR:
        {
            logType = LOG_WARNING_STR;
        }
            break;
            
        default:
            break;
    }
    if(level >= LOG_LEVEL_BASE)
    {
//        NSString *logStr = [NSString stringWithFormat:@"%@ %@, %s, line:%zu, log:%@;;", logType, [Utils getTodayHHMMSS] ,func, line, log];
//        NSTimeInterval dif = ([HOUtils getCurrentTime] - recoredTime)*1000;
//        NSString *logStr = [NSString stringWithFormat:@"%@,   useTime:%f     ,  line:%zu, log:%@", logType,dif, line, log];
        NSString *logStr = [NSString stringWithFormat:@"%@, | %s, | line:%zu, log:%@", logType,func, line, log];
        NSLog(@"log:%@", logStr);
        CLS_LOG(@"logStr%@", logStr);
        //[Utils setLogRecString:logStr];
        recoredTime = [HOUtils getCurrentTime];
        //[Utils setLogRecString:[logStr retain]];
        //[logStr release];
    }
    
    

}



void LogExitGo(const char * func,size_t line,NSString * format,...)
{
//        [Utils saveLog];
//    [Utils setLogRecString:@"app exit!"];
}
@end
